const Sequelize = require('sequelize')
const glob = require('glob')
const { resolve } = require('path')
const { db } = require('../config')
// CREATE DATABASE IF NOT EXISTS 20191125airplane DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
// use mysql;
// update mysql.user set authentication_string=password('@flan_mysql_yhao_010') where user='root'; 
// flush privileges;
/**
 *
 * 配置数据库
 *
 * 第一个参数 name    数据库名字
 * 第二个参数 user      数据库名字
 * 第三个参数 password  数据库密码
 */

exports.sequelize = new Sequelize(db.name, db.user, db.password, {
  host: 'localhost',
  // port: 3306,
  dialect: 'mysql',
  pool: {
    max: 5,
    min: 0,
    acquire: 30000,
    idle: 10000
  },
  logging: sql => {
    // console.log(sql)
  },
  timezone: '+08:00'
})

exports.initAllSchema = () => {
  glob.sync(resolve(__dirname, './tables', '**/*.js')).forEach(item => {
    require(item)
  })
}
